package com.gitee.wsl.struct.tree.ext

import com.gitee.wsl.ext.collection.skipUntil
import com.gitee.wsl.struct.tree.Tree
import com.gitee.wsl.struct.tree.TreeElement
import com.gitee.wsl.struct.tree.iterator.TreeNodeIteratorType

fun <T,E: TreeElement<T, E>> Tree<T, E>.find(data:T):TreeElement<T, E>? = walkDepthFirst().find { it.data == data }

fun <T,E: TreeElement<T, E>> TreeElement<T, E>.find(value:T):TreeElement<T, E>?
        = iterator(TreeNodeIteratorType.PreOrder).skipUntil { it.data == value }

fun <T,E: TreeElement<T, E>> TreeElement<T, E>.findChild(node:TreeElement<T, E>):TreeElement<T, E>?
        = iterator(TreeNodeIteratorType.PreOrder).skipUntil { it == node }